//创建一个管道，父进程读，子进程写
//fds[0] -- 读
//fds[1] -- 写
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(void)
{
	//创建文件描述符数组
	int fds[2];
	//如果创建失败则返回-1
	if ( pipe(fds) == -1) {
		perror("pipe error");
		exit(1);
	}
	//子进程写
	if ( fork() == 0 ) {
		close(fds[0]);
		write(fds[1], "abc\n", 4);
		close(fds[1]);
		exit(0);
	}
	else {
		close(fds[1]);
		char buff[100] = {};
		//阻塞读
		read(fds[0], buff, 100);
		close(fds[1]);
		printf("%s\n", buff);
		exit(0);
	}
}
